package cn.dengta.webapp.trade.service;

import cn.dengta.common.model.TimeInterval;
import cn.dengta.common.web.Page;
import cn.dengta.webapp.base.service.BaseServiceImpl;
import cn.dengta.webapp.trade.dao.UserGoldLogDao;
import cn.dengta.webapp.trade.entity.UserGoldLog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import static cn.dengta.webapp.trade.entity.UserGoldLog.*;

/**
 * 用户金币操作记录 服务实现类
 *
 * @author Ready
 * @since 2022-11-21
 */
@Service
public class UserGoldLogService extends BaseServiceImpl<UserGoldLog, UserGoldLogDao, Long> {

	public Page<UserGoldLog> findPage(Page<UserGoldLog> page, Long userId) {
		QueryWrapper<UserGoldLog> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(USER_ID, userId);
		queryWrapper.orderByDesc(ID);
		return selectPage(page, queryWrapper);
	}

	public Page<UserGoldLog> findAdminList(Page<UserGoldLog> page, TimeInterval integral, Long userId, Integer tradeType, Integer flow) {
		QueryWrapper<UserGoldLog> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(flow != null, FLOW, flow)
				.eq(tradeType != null, TRADE_TYPE, tradeType)
				.eq(userId != null, USER_ID, userId);
		if (integral != null) {
			queryWrapper.between(integral != null, ADD_TIME, integral.getFinalBegin(), integral.getFinalEnd());
		}
		queryWrapper.orderByDesc(ID);
		return selectPage(page, queryWrapper);
	}

}
